#include "glmh.h"

void glmhCorrect(GLMmodel* model)
{
	if ((GLint) model->triangles[0].vindices[0] > 0)
		return;

	for (unsigned int i = 0; i < model->numtriangles; i++) {

		GLuint *indices;
		int num;

		GLMtriangle* glm_triangle = &model->triangles[i];

		indices = glm_triangle->vindices;
		num = model->numvertices;

		for (int j = 0; j < 3; j++) {
			GLint index = indices[j];
			if (index < 0)
				indices[j] = num + index + 1;
		}

		indices = glm_triangle->nindices;
		num = model->numnormals;

		for (int j = 0; j < 3; j++) {
			GLint index = indices[j];
			if (index < 0)
				indices[j] = num + index + 1;
		}

		indices = glm_triangle->tindices;
		num = model->numtexcoords;

		for (int j = 0; j < 3; j++) {
			GLint index = indices[j];
			if (index < 0)
				indices[j] = num + index + 1;
		}

	}
}